<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 * 
 * 清理数据类
 * 
 */
namespace osc\admin\controller;
use osc\common\controller\AdminBase;
use think\Db;
class Clear extends AdminBase{
	
	protected function _initialize(){
		parent::_initialize();
	}
	
	//清空数据库中的测试数据,生成安装sql
    function clear_test_data(){
    	
		$table=array(
			'address','admin','agent','agent_apply','agent_bonus','agent_cash_apply','agent_level',
			'wechat_news_reply','wechat_rule','wechat_share','wechat_text_reply','cart','test','comment','member',
			'member_auth_group_access','member_wishlist','order','order_goods','order_history','order_option',
			'order_total','points','predeposit','refund','user_action'
		);
		
		foreach ($table as $k => $v) {
			Db::execute('TRUNCATE '.config('database.prefix').$v);
		}
		
		$config=array(
			'SITE_TITLE'=>'oscshop',
			'SITE_NAME'=>'oscshop',
			'SITE_DESCRIPTION'=>'oscshop',
			'SITE_KEYWORDS'=>'oscshop',
			'SITE_URL'=>'o2.com',
			'SITE_ICP'=>'闽ICP备12345678号',
			'TELEPHONE'=>'15711573244',
			'qq'=>'123456789',
			'administrator'=>'',
			'SHORT_URL'=>'o2.com',
			'kefu_qq'=>'',
			'kuaidi100_key'=>''
		);
		foreach ($config as $k => $v) {
			//dump($k.'-'.$v);
			Db::name('config')->where('name',$k)->update(array('value'=>$v));
		}
		
		//die;
		
		Db::name('config')->where('name','PWD_KEY')->delete();
		Db::name('config')->where('use_for','payment')->update(array('value'=>''));
		
		$dirtool = new \oscshop\Dir();   
   		$dirtool->delDir(ROOT_PATH.'runtime/');  
		$dirtool->delDir(ROOT_PATH.'public/uploads/cache/images/');
		unlink(ROOT_PATH.'oscshop/database.php');
		
		//return array('success'=>'清除成功');
		die('清除成功');
    }
	
	function clear_all(){
		
		$table=array(
			'article','article_category','article_data','attribute','attribute_value','category','category_to_attribute',
			'category_to_brand','goods','goods_attribute','goods_brand','goods_description','goods_discount','goods_image',
			'goods_mobile_description_image','goods_option','goods_option_value','goods_to_category','group_buy','group_buy_images',
			'length_class','option','option_value','plugin_slide',
			
			'address','agent','agent_apply','agent_bonus','agent_cash_apply','agent_level',
			'wechat_news_reply','wechat_rule','wechat_share','wechat_text_reply','cart','test','comment','member',
			'member_auth_group_access','member_wishlist','order','order_goods','order_history','order_option',
			'order_total','order_status','points','predeposit','refund','user_action','refund_reason',
			'transport','transport_extend','weight_class'
		);
		
		foreach ($table as $k => $v) {
			Db::execute('TRUNCATE '.config('database.prefix').$v);
		}
		
		die('success');
		
	}
	
}
?>